#pragma once
#ifndef CLIB_RING_H
#define CLIB_RING_H

#include "clib_type.h"
#include "clib_spinlock.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum clib_ring_type_s {
    clib_ring_single,
    clib_ring_multi,
} clib_ring_type_t;

typedef struct clib_ring_s {
    u32_t               size;
    u32_t               head;
    u32_t               tail;
    u32_t               type;
    clib_spinlock_t     lock;
    void               *data[];
} clib_ring_t;

i32_t clib_ring_init(clib_ring_t* ring, u32_t size, clib_ring_type_t type);

i32_t clib_ring_elem_size(clib_ring_t* ring);

i32_t clib_ring_elem_empty(clib_ring_t* ring);

i32_t clib_ring_enqueue_elem(clib_ring_t* ring,void *obj);

i32_t clib_ring_enqueue_bulk_elem(clib_ring_t* ring,void **obj, u32_t size);

i32_t clib_ring_dequeue_elem(clib_ring_t* ring, void **obj);

i32_t clib_ring_dequeue_bulk_elem(clib_ring_t* ring,void **obj, u32_t size);

#ifdef __cplusplus
}
#endif

#endif